package com.zhu.controller;

import com.zhu.pojo.Expend;
import com.zhu.pojo.Transform;
import com.zhu.pojo.Type;
import com.zhu.pojo.Way;
import com.zhu.service.ExpendService;
import com.zhu.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TypeController {
    @Autowired
    TypeService typeService;


    @CrossOrigin //解决跨域问题
    @GetMapping("/api/type/{username}")
    public List<Type> list(@PathVariable("username") String username){
        return typeService.typeList(username);
    }


    @CrossOrigin //解决跨域问题
    @PostMapping("/api/saveType")
    public String save(@RequestBody Type type) {
        boolean flag = typeService.save(type);
        if(flag){
            return "success";
        }else {
            return "false";
        }
    }

    @CrossOrigin //解决跨域问题
    @PostMapping("/api/updType")
    public String upd(@RequestBody Type type) {
        boolean flag = typeService.upd(type);
        if(flag){
            return "success";
        }else {
            return "false";
        }
    }

    @CrossOrigin //解决跨域问题
    @GetMapping("/api/delType/{id}")
    public String upd(@PathVariable("id") int id) {
        boolean flag = typeService.del(id);
        if(flag){
            return "success";
        }else {
            return "false";
        }
    }

    @CrossOrigin //解决跨域问题
    @GetMapping("/api/typeAdmin")
    public List<Type> list(){
        return typeService.typeListByAdmin();
    }



}

